package com.tencent.wxcloudrun.service.impl;

import com.tencent.wxcloudrun.dao.CategoryMapper;
import com.tencent.wxcloudrun.model.Categories;
import com.tencent.wxcloudrun.service.CategoriesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author lichongbing
 * @version 1.0.0
 * @createdate 2023/2/17 17:01
 * @description: TODO
 */
@Service
public class CategoriesServiceImpl implements CategoriesService {
    @Autowired
    private CategoryMapper categoryMapper;
    @Override
    public List<Categories> getCategory() {
        return categoryMapper.getCategory();
    }

    @Override
    public Categories getCategory(int id) {

        return categoryMapper.getCategorys(id);
    }

    @Override
    public int addCategory(Categories categories) {
        Map<String, Object> data = new HashMap<>();
        data.put("id", categories.getId());
        data.put("count", 0.0F);
        data.put("description", categories.getDescription());
        data.put("name", categories.getName());
        return categoryMapper.addCategory(data);
    }

    @Override
    public Categories getCategoryInfo(String id) {
        return categoryMapper.getCategorys(Integer.parseInt(id));
    }
}
